#include "InsTempContext.h"

using namespace std;

InsTempContext::InsTempContext():m_tempSock(NULL),m_tempOvl(),m_tempBuffer(),m_tempWeakRefBuf(),
	m_tempRequestBuffer(NULL),m_partialTransIndex(0),m_tempHttpResponseHeader(new HttpResponseHeader())
{
	InitAsyncParam(&m_tempOvl,&m_tempBuffer);
}

InsTempContext::~InsTempContext()
{
	if(m_tempSock!=NULL)
	{
		shutdown(m_tempSock,SD_BOTH);
		closesocket(m_tempSock);
	}
	FreeTempRequestBuffer();
	delete []m_tempBuffer.buf;
	if(m_tempHttpResponseHeader!=NULL)
	{
		delete m_tempHttpResponseHeader;
	}
}

void InsTempContext::FreeTempRequestBuffer()
{
	if(m_tempRequestBuffer!=NULL)
	{
		delete m_tempRequestBuffer;
		m_tempRequestBuffer=NULL;
	}
}

void InsTempContext::InitAsyncParam(OVERLAPPED *ovl,WSABUF *buffer)
{
	::ZeroMemory(ovl,sizeof(OVERLAPPED));
	buffer->buf=new char[CLIENTCONTEXT_BUFFER_SIZE];
	buffer->len=CLIENTCONTEXT_BUFFER_SIZE;
}